import request from "@/utils/request";

const FLOW_BASE_URL = "/system/flowNodeTask";

const FlowNodeTaskAPI = {
  /**
   * 根据id 获取流程节点任务详情
   * @param id 任务id
   */
  loadDetail(id: string) {
    return request<any, FlowNodeTaskDetailVo>({
      url: `${FLOW_BASE_URL}/loadDetailId/${id}`,
      method: "get",
    });
  },

  /**
   * 添加流程节点任务
   * @param data 表单数据
   */
  create(data: FlowNodeTaskDetailVo) {
    return request<any, FlowNodeTaskVo>({
      url: `${FLOW_BASE_URL}/add`,
      method: "post",
      data,
    });
  },

  /**
   * 修改流程节点任务
   * @param data 表单数据
   */
  update(data: FlowNodeTaskDetailVo) {
    return request<any, FlowNodeTaskVo>({
      url: `${FLOW_BASE_URL}/update`,
      method: "post",
      data,
    });
  },

  /**
   * 删除任务
   * @param id 任务id
   */
  deleteById(id: string) {
    return request({
      url: `${FLOW_BASE_URL}/delete/${id}`,
      method: "get",
    });
  },
};

export default FlowNodeTaskAPI;

/** 流程节点任务对象 */
export interface FlowNodeTaskVo {
  /** ID */
  id?: string;
  /** 流程模板id */
  flowId?: string;
  /** 流程节点id */
  flowNodeId?: string;
  /** 名称 */
  name: string;
  /** 描述 */
  remark?: string;
  /** 角色 */
  activityRole: string;
  /** 候选人类型 */
  candidateType: string;
  /** 候选人类型id */
  candidateId?: string;
  /** 候选名称 */
  candidateName?: string;
  /** 候选人数量 */
  candidateNum?: number;
  /** 用户id */
  userId?: number;
  /** 用户名称 */
  username?: string;
  /**系统内置任务 */
  systemd?: boolean;
  /** 审核人id */
  auditorId?: string;
  /** 审核人名称 */
  auditorName?: string;
  /** 审核类型 */
  auditType?: string;
}

/** 流程节点任务明细 */
export interface FlowNodeTaskDetailVo extends FlowNodeTaskVo {
  /** 数据填报规则 */
  flowNodeTaskDataConfigs: FlowNodeTaskDataConfig[];
}

/** 流程节点任务数据 填报规则 */
export interface FlowNodeTaskDataConfig {
  /** ID */
  id?: string;
  /** 流程模板id */
  flowId?: string;
  /** 流程节点id */
  flowNodeId?: string;
  /** 任务id */
  taskId?: string;
  /** 属性类型 */
  dataType: string;
  /** 属性 */
  property: string;
  /** 属性值 */
  val: string;
  /** 备选项数据 多个用，分割 */
  options: string;
  /** 是否系统内置任务 */
  systemd?: boolean;
}

//************ 枚举 ********** */
// 活动角色
export enum FlowActivityRole {
  ASSIGNEE = "ASSIGNEE",
  ACTOR = "ACTOR",
  AUDITOR = "AUDITOR",
}
export const FLOW_ACT_ROLE_LABEL: IConstant = {
  [FlowActivityRole.ASSIGNEE]: "责任人",
  [FlowActivityRole.ACTOR]: "参与者",
  [FlowActivityRole.AUDITOR]: "审核人",
};

// 审核节点校色
export const FLOW_ACT_AUDITOR_ROLE_LABEL: IConstant = {
  [FlowActivityRole.AUDITOR]: "审核人",
};

export const FLOW_ACT_BUSINESS_ROLE_LABEL: IConstant = {
  [FlowActivityRole.ASSIGNEE]: "责任人",
  [FlowActivityRole.ACTOR]: "参与者",
};

// 候选人来源
export enum FlowCandidatType {
  DEP = "DEP",
  JOB = "JOB",
  ROLE = "ROLE",
  USER = "USER",
  ASSIGN = "ASSIGN",
}
export const FLOW_CANDIDAT_TYPE_LABEL: IConstant = {
  [FlowCandidatType.DEP]: "部门",
  [FlowCandidatType.JOB]: "岗位",
  [FlowCandidatType.ROLE]: "用户角色",
  [FlowCandidatType.USER]: "指定人员",
  // [FlowCandidatType.ASSIGN]: "上一节点人员指定",
};

// 填报项数据类型
export enum FlowTaskDataType {
  TEXT = "TEXT",
  NUMBER = "NUMBER",
  RELATED = "RELATED",
  HREF = "HREF",
  OPTION = "OPTION",
  DATE = "DATE",
  DATETIME = "DATETIME",
  FILE = "FILE",
}
export const FLOW_TASK_DATA_TYPE_LABEL: IConstant = {
  [FlowTaskDataType.TEXT]: "文本",
  [FlowTaskDataType.NUMBER]: "数字",
  // [FlowTaskDataType.RELATED]: "关联数据",
  // [FlowTaskDataType.HREF]: "超链接",
  [FlowTaskDataType.OPTION]: "选项",
  [FlowTaskDataType.DATE]: "日期",
  [FlowTaskDataType.DATETIME]: "日期时间",
  [FlowTaskDataType.FILE]: "文件",
};
